package com.miao.websecurity.controller;

import com.miao.common.entity.R;
import com.miao.websecurity.entity.SysApi;
import com.miao.websecurity.service.SysApiService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author MiaoWenqing
 * @description: TODO
 * @date 2021/2/1 16:47
 */

@RestController
@RequestMapping("/admin/api")
public class ApiController {


    @Resource
    private SysApiService sysApiService;

    @PostMapping("/add")
    public R roleAdd(@RequestBody SysApi sysApi){

        if (this.sysApiService.save(sysApi)){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @GetMapping("/all")
    public R apiList(){
        List<SysApi> list = this.sysApiService.list();
        return R.ok(list);
    }


    @GetMapping("/del")
    public  R apiDel( String apiId){
        if (this.sysApiService.removeById(apiId)) {
            return R.ok();
        }else {
            return R.error();
        }
    }

    @PostMapping("/edit")
    public  R apiEdit( @RequestBody SysApi sysApi){

        if (this.sysApiService.saveOrUpdate(sysApi)){
            return R.ok();
        }else {
            return R.error();
        }

    }




}
